package com.vancouver.knows.ui.base;

import android.Manifest;
import android.os.Bundle;
import com.vancouver.knows.LocationController;

import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;

public class LocationActivity extends BaseActivity{

	private static final int RC_LOCATION = 489;

	protected LocationController mLocationController;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mLocationController = new LocationController(this,isUpdateLocation());
		mLocationController.onCreate();
	}

	public LocationController getLocationController() {
		return mLocationController;
	}

	@Override
	protected void onStart() {
		startLocationController();
		super.onStart();
	}

	@AfterPermissionGranted(RC_LOCATION)
	private void startLocationController() {
		String[] perms = {Manifest.permission.ACCESS_FINE_LOCATION};
		if (EasyPermissions.hasPermissions(this, perms)) {
			mLocationController.onStart();
		} else {
			EasyPermissions.requestPermissions(this, "Need location permissions.",
					RC_LOCATION, perms);
		}
	}

	@Override
	public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
		super.onRequestPermissionsResult(requestCode, permissions, grantResults);
		EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
	}

	@Override
	protected void onStop() {
		mLocationController.onStop();
		super.onStop();
	}

	protected boolean isUpdateLocation(){
		return false;
	}

}
